<template>
  <!-- <div id="pdfBox" v-html="html"> </div> -->
  <div></div>
  <iframe id="myIframe" :src="url" @load="adjustIframe" :type="type" width="100%" height="100%" />
</template>
<script lang="ts" setup>
  import type { CSSProperties } from 'vue';
  import { ref, unref, computed, onMounted, nextTick } from 'vue';
  import { Spin } from 'ant-design-vue';
  import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
  import { propTypes } from '/@/utils/propTypes';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight';
  import { useRoute, useRouter } from 'vue-router';

  const heightRef = ref(window.innerHeight);
  const { currentRoute } = useRouter();

  const getWrapStyle = computed((): CSSProperties => {
    return {
      height: `${unref(heightRef)}px`,
    };
  });

  const url = ref<any>('');
  const html = ref<any>('');
  const type = ref('');

  onMounted(async () => {
    await nextTick();

    if (currentRoute.value.query) {
      url.value = currentRoute.value.query.url;
      if (currentRoute.value.query.type && currentRoute.value.query.type == 'pdf')
        type.value = 'application/x-google-chrome-pdf';
    }
    console.log('currentRoute.value.query', currentRoute.value.query, 'url', url.value);

    // html.value = `<embed
    //   id="pdf-embed"
    //   type="application/x-google-chrome-pdf"
    //   src="chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/5df505bb-f151-4c4f-b457-5810ea83aa11"
    //   original-url="${url}"
    //   background-color="4293322470"
    //   embed-top-offset="41"
    //   javascript="allow"
    //   pdfdigsigpolicyenabled=""
    //   pdffreetextenabled=""
    //   pdfviewrecoveryenabled=""
    //   pdfoopifscrollbarenabled=""
    //   pdffastscrollenabled=""
    //   stream_timestamp="590514640727"
    //   first-page-separator="4"
    //   class="absolute-embed"
    //   height="4546"
    //   width="804"
    // />`;
  });

  function adjustIframe() {
    var ifm = document.getElementById('myIframe');
    ifm.height = document.documentElement.clientHeight - 50;
    ifm.width = document.documentElement.clientWidth - 10;
  }
</script>
<style lang="less" scoped></style>
